﻿
Ext.namespace('FantastPlatform', 'FantastPlatform.UI');
FantastPlatform.UI.LogReplyGrid = function (config) {
    Ext.apply(this, config);
    var fileStore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: '../Service/WorkLog.aspx?Action=GetReplyByLogId'
        }),
        reader: new Ext.data.JsonReader({
            root: 'topics',
            totalProperty: 'totalCount',
            id: 'Id',
            fields: ['Id', 'Content', 'PoliceMan', 'ReplyDate']
        }),
        remoteSort: true
    });

    this.store = fileStore;
    var paperBar = new FantastPlatform.Common.PapeToolBar({
        store: fileStore,
        noSort: true,
        defaultNum: 10
    });
    this.paperBar = paperBar;
    this.bbar = paperBar;
    this.pageNumber = paperBar.pageSize;

    function renderTopic(value, p, record) {
        return String.format(
                '<b>回复人：{0}</b><br/>回复时间：{1}<br/>内容：{2}',
                 record.data.PoliceMan, record.data.ReplyDate, record.data.Content);
    }
    function renderLast(value, p, r) {
        return String.format('{0}<br/>by {1}', r.data['AnswerTime'], r.data['Answerer']);
    }
    var nm = new Ext.grid.RowNumberer();
    this.columns = [{
        header: "ID",
        dataIndex: "Id",
        hidden: true
    }, {
        header: "已回复的记录",
        dataIndex: 'Content',
        //  width: 420,
        width: '100%',
        renderer: renderTopic,
        sortable: true
    }
];

    FantastPlatform.UI.LogReplyGrid.superclass.constructor.call(this, {
        loadMask: { msg: '正在加载数据...' },
        viewConfig: {
            forceFit: true,
            enableRowBody: true,
            showPreview: true
        }
    });
};

Ext.extend(FantastPlatform.UI.LogReplyGrid, Ext.grid.GridPanel, {
    CompleteQuestion: function () {
        this.store.removeAll();
        this.store.baseParams = { data: '{\"IsAnswered\":\"true\"}' };
        this.store.load({ params: { start: 0, limit: this.paperBar.getPageNumber()} });
    },
    
       
    onUpdata: function () {
        this.store.removeAll();
        this.store.reload();
    }
});